package com.example.sj.baseapplication.Base;

import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

/**
 * Created by Administrator on 2017/11/3.
 */

public abstract class BaseFragment<B extends ViewDataBinding> extends Fragment {
    private B binding;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding= DataBindingUtil.inflate(inflater,setlayoutid(),container,false);
        init(binding);
        return binding.getRoot();
    }
    public abstract int setlayoutid();
    public abstract void init(B binding);
    public void toast(Object s){
        if (getContext()==null)
            return;
        Toast.makeText(getContext(), String.valueOf(s), Toast.LENGTH_SHORT).show();
    }
    //基类
public void addToolBar(final LinearLayout linearLayout, Toolbar toolbar){
    Toolbar.LayoutParams params = new Toolbar.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT,
            Toolbar.LayoutParams.WRAP_CONTENT);
    // 取控件aaa当前的布局参数
    params.height = dip2px(45.0f);        // 当控件的高强制设成150象素
    params.width=Toolbar.LayoutParams.MATCH_PARENT;
    linearLayout.addView(toolbar,0,params);
}
public int dip2px(float dip){
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,dip,getResources().getDisplayMetrics());
}
//调用
/**
 Toolbar toolbar=new MyToolBar(this)
     .init().addTitle("登陆")
     .addLogo()
     .setOverflowIcon()
     .addHome(0, new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    finish();
    }
    });
 this.addToolBar(binding.lineToolbar,toolbar);
 */


}

